package com.cm.sys.system.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cm.sys.system.dao.UserRoleMapper;
import com.cm.sys.system.entity.UserRole;
import com.cm.sys.system.service.UserRoleService;

/***
 * 角色用户管理接口
 * 
 * @author yxq18
 * @date 2020/01/02
 */
@Service
public class UserRoleServiceImpl implements UserRoleService {

    @Autowired
    private UserRoleMapper userRoleMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int insert(UserRole record) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public UserRole selectByPrimaryKey(Integer id) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public List<UserRole> selectAll() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public int updateByPrimaryKey(UserRole record) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public List<UserRole> selectAll(Integer userId) {

        List<UserRole> userRole = userRoleMapper.selectRoles(userId);
        return userRole;
    }

    @Override
    public int insertBatch(List<UserRole> record) {
        userRoleMapper.insertBatch(record);
        return 0;
    }

    @Override
    public int deleteByUserId(Integer userId) {

        userRoleMapper.deleteByUserId(userId);
        return 0;
    }

    @Override
    public List<Integer> getRoleIdByUserId(Integer userId) {
        // TODO Auto-generated method stub
        List<Integer> roleIds = userRoleMapper.getRoleIdByUserId(userId);
        return roleIds;
    }

    //通过组id删除user_role表中的关联数据
    @Override
    public Integer deleteByRoleId(Integer roleId) {
        try {
            userRoleMapper.deleteByRoleId(roleId);
            return 1;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    //通过用户id查询所有的用户
    @Override
    public List<UserRole> selectByUserId(Integer userId) {
        return userRoleMapper.selectRoles(userId);
    }

    @Override
    public List<UserRole> selectByRoleId(Integer roleId) {
        return userRoleMapper.selectByRoleId(roleId);
    }

}
